<?php
/**
 * Created by 长毋相忘c.
 * 文件用途描述 :
 * Date: 2018/2/19/019
 * Time: 15:54
 */

namespace app\api\model;


class Order extends BaseModel
{
    protected $hidden = ['user_id', 'delete_time', 'update_time'];
   protected $autoWriteTimestamp=true;

//读取器，用来自动将json字符串转换为json对象
    public function getSnapItemsAttr($value){
        if (empty($value)){
            return null;
        }
        return json_decode($value);
    }
//读取器，用来自动将json字符串转换为json对象
    public function getSnapAddressAttr($value){
        if (empty($value)){
            return null;
        }
        return json_decode($value);
    }

    //根据用户ID获取分页信息
    //$uid用户ID $page当前页（默认为1）size 每页显示条数
    public static function getSummaryByUser($uid,$page=1,$size=15){
    $pagingData = self::where('user_id','=',$uid)
        ->order('create_time','desc')//根据事件倒叙显示
        ->paginate($size,true,['page'=>$page]);//分页核心代码
    return $pagingData;
}

    public static function getSummaryByPage($page=1, $size=20){
        $pagingData = self::order('create_time desc')
            ->paginate($size, true, ['page' => $page]);
        return $pagingData ;
    }
}